package cn.kogee.controller;

import cn.kogee.domian.Product;
import cn.kogee.domian.Store;
import cn.kogee.domian.User;
import cn.kogee.feignclient.OrdetFeign;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.filter.OrderedFilter;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@DefaultProperties(defaultFallback = "fallbackGetById")
public class Ordercontroller {
    @Autowired
    private OrdetFeign ordetFeign;
    @HystrixCommand
    @GetMapping("/{id}")
    public Object getprodect(@PathVariable("id") Long id){
        return ordetFeign.findById(id);
    }
    @PutMapping
    public Object addProduct(@RequestBody Product product){
        return ordetFeign.add(product);
    }
    @GetMapping("/sto/{id}")
    public Object getstore(@PathVariable("id") Long id){
        return ordetFeign.getSto(id);
    }
    @PutMapping("/up")
    public Object upstore(@RequestBody Store store){
        return ordetFeign.upstore(store);
    }
    public Object fallbackGetById(){//@PathVariable("id")Long id统一托底不需要改注解
        return new User(-1L,"统一托底方法触发熔断机制","服务被熔断，请稍后重试！！");
    }
}
